
Vue.component2('a_1_0_2_5_0', {  
    template: `
        <div  :class="{ 'a_1_0_2_5_0_lines test': data.true, 'a_1_0_2_5_0_lines_onclick': data.onclick_flag }" @click="handle_click" v-show="show_flag">
        <span :style="'padding-left: '+data._space_+'px;'"></span>
        <span  v-if="data.icon1_show_flag" class="icon iconfont icon-add_version"></span>
        
        <span  class="a_1_0_2_5_1_hid_line" style="color:#bcbcbc">{{data.version}}.{{data.version_name}}</span>
        <div style="display:inline-block;flex:1;">
        <div style="display:flex;
    justify-content: flex-end;
    display: flex;">
    
        <div  @click="click1($event,k)" v-for="(v,k) in data.icon_data"
        :key="k">
         <a_1_0_3_0_0 style="display: inline-block;"
         :deepcopy_data="v"></a_1_0_3_0_0>
        </div>
        </div>
        </div>


        <el-dialog
        title="更新代码(上传组件文件夹)"
        :visible.sync="update_my_temp_from_flag"
        width="30%">
        <input ref="add_temp" type="file" webkitdirectory directory multiple>
        <span slot="footer" class="dialog-footer">
          <el-button @click="update_my_temp_from_flag = false">取消</el-button>
          <el-button @click="update">确 定</el-button>
        </span>
      </el-dialog>


















        </div>
`,
data(){
    return{
        update_my_temp_from_flag:false,
        show_flag:true,
        data:{
          version_name:'',
          version:"",
          onclick_flag:false,
            tree_data:{},//
            icon_data:{},
            icon1_show_flag:true,
            click:null,
            click_obj:null,
            true:true,
            false:false,
            close:true,
            name:"",
            _space_:0,
        }
    }
},
methods:{

    update:function(){this.data.update_temp()},
    handle_click:async function(event){
      //点击当前 高亮显示
      try{console.log("高亮",this.data.path);
this.data.tree_data.set_onclick_flag(this.data.path)}catch{}
        return
        /* console.log("我点击了一次")*/
        try{
            /* console.log("?")*/
            if(!this.data.tree_data.check_dct[this.data.path]){
                await this.data.刷新前端组件();
            }
            /*console.log("?2")*/}
        catch{}

        if (this.data.click){
            try{
                this.data.click(event)
            
                // console.log("start click2")
            }
            catch{}
            return 
        }


        if (this.data.click_obj){
            try{
                lhp_run_func(this.data.click_obj.func,this.data.click_obj.args)
            
                // console.log("start click3")
            }
            catch{}
            return 
        }
        try{
            this.data.click_handle(this.data.path,this.data.close);
        }catch{}
    },
    click1:async function(event,k){
       /* console.log(',,,',this.data.icon_data[k].click)*/
        lhp_run_func(this.data.icon_data[k].click);
        if(!this.data.click_stop){event.stopPropagation();}//阻止父级

    }
},

mounted:function(){
    /*console.log("210的deepcopydata",_this.deepcopy_data)*/
    let urls=_this.deepcopy_data.tree_data.url;
    let check_dct=_this.deepcopy_data.tree_data.check_dct;
_this.data.获取用户的前端组件库组件版本列表_flag=false;
_this.data.获取用户的前端组件库组件版本列表_request=request______({method:'post',url:urls.获取用户的前端组件库组件版本列表_url});
_this.data.获取用户的前端组件库组件版本列表_recv=function(received_data){
    /*console.log("接收数据",received_data,_this.data.path);*/
    _this.data.tree_data.set_dict(received_data.data,_this.data.path);
    check_dct[_this.data.path]=received_data;
    _this.data.获取用户的前端组件库组件版本列表_flag=true;
}
_this.data.刷新前端组件=async function(){

    if(!_this.data.dir1_id){
        let path_l=_this.data.path.split(".");
        _this.data.dir1_id=path_l[path_l.length-3];
        _this.data.dir2_id=path_l[path_l.length-2];
        _this.data.temp_id=path_l[path_l.length-1];
    }
    let count=0;
    _this.data.获取用户的前端组件库组件版本列表_flag=false;
    _this.data.获取用户的前端组件库组件版本列表_request({
        body_data:{dir1_id:_this.data.dir1_id,dir2_id:_this.data.dir2_id,temp_id:_this.data.temp_id,version_id:_this.data.version_id},
        execute_lst:[
                      {
                        'type':'func',
                        'func':_this.data.获取用户的前端组件库组件版本列表_recv,
                        'args':['received_data'],
                      },
                    ]
    });
    await time_sleep(20);
    while(1){
        count++;
        await time_sleep(1);
        if(_this.data.获取用户的前端组件库组件版本列表_flag==true){break}
        if(count>500){Vue.prototype.$notify({type: 'error',message: '获取前端目录2列表失败'});break}
    }
}






_this.data.修改前端组件版本属性_request=request______({method:'post',url:urls.修改前端组件版本属性_url});

findKeydeepcopy=function (obj, path = []){
  // 遍历对象的所有属性  
  for (let key in obj) {  
      if (obj.hasOwnProperty(key)) {  
          // 更新当前路径  
          let currentPath = [...path, key];  

          // 如果当前属性的 key 是 'aaa'，返回路径  
          if (key === 'deepcopy_data') {  
              return currentPath;  
          }  

          // 如果当前属性是对象，递归调用  
          if (typeof obj[key] === 'object' && obj[key] !== null) {  
              let result = findKeydeepcopy(obj[key], currentPath);  
              if (result) {  
                  return result;  
              }  
          }  
      }  
  }  

  // 如果没有找到 key 为 'aaa' 的对象，返回 null  
  return null;  
}  
_this.data.修改前端组件版本属性_recv=function(received_data){
    console.log("接收数据",received_data);
    _this.data.修改前端组件版本属性_flag=true;
    let lst=findKeydeepcopy(received_data);
    let copy_data=received_data;
    for(let i=0;i<lst.length;i++){copy_data=copy_data[lst[i]]}
    _this.data.tree_data.change_deepcopy_data(_this.data.path,copy_data);
}
_this.data.修改前端组件版本属性=async function(name){

    if(!_this.data.dir1_id){
        let path_l=_this.data.path.split(".");
        _this.data.dir1_id=path_l[path_l.length-4];
        _this.data.dir2_id=path_l[path_l.length-3];
        _this.data.temp_id=path_l[path_l.length-2];
        _this.data.version_id=path_l[path_l.length-1];
    }
    let count=0;
    _this.data.修改前端组件版本属性_flag=false;
    _this.data.修改前端组件版本属性_request({
        body_data:{name:name,dir1_id:_this.data.dir1_id,dir2_id:_this.data.dir2_id,temp_id:_this.data.temp_id,version_id:_this.data.version_id},
        execute_lst:[
                      {
                        'type':'func',
                        'func':_this.data.修改前端组件版本属性_recv,
                        'args':['received_data'],
                      },
                    ]
    });
    await time_sleep(20);
    while(1){
        count++;
        await time_sleep(1);
        if(_this.data.修改前端组件版本属性_flag==true){break}
        if(count>500){Vue.prototype.$notify({type: 'error',message: '修改前端组件版本属性失败'});break}
    }
}
//生成随机数
_this.data.generateRandomString=function (length){  
  if (_this.data.generateRandomString_val){
    return _this.data.generateRandomString_val
  }
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';  
  let result = '';  
  const charactersLength = characters.length;  
  for (let i = 0; i < length; i++) {  
      const randomIndex = Math.floor(Math.random() * charactersLength);  
      result += characters[randomIndex];  
  }  
  _this.data.generateRandomString_val=result
  return result;  
}  
_this.data.icon_data={
  297:{
    icon_class:"icon iconfont icon-fuzhi",
    hovertext:"复制组件id",
    add_show:false,
    click:async function(){
      if(!_this.data.dir1_id){
        let path_l=_this.data.path.split(".");
        _this.data.dir1_id=path_l[path_l.length-4];
        _this.data.dir2_id=path_l[path_l.length-3];
        _this.data.temp_id=path_l[path_l.length-2];
        _this.data.version_id=path_l[path_l.length-1];
    }
    let copy_data=`a_${cookie_read("easyedit_userid")}_${_this.data.dir1_id}_${_this.data.dir2_id}_${_this.data.temp_id}_${_this.data.version_id}`
      copy_text(copy_data); 
      Vue.prototype.$notify({type: 'success',message: '已拷贝:'+copy_data})

  },
},
  
  298:{
    icon_class:"icon iconfont icon-write",
    hovertext:"修改前端组件版本属性",
    add_show:false,
    click:async function(){
        _this.$prompt('修改前端组件(名称)', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
          }).then(({ value }) => {
           _this.data.修改前端组件版本属性(value);
          }).catch(() => {
            _this.$message({
              type: 'info',
              message: '取消输入'
            });       
          });},
    },
  299:{
      icon_class:"icon iconfont icon-download",
      hovertext:"下载此组件代码",
      add_show:false,
      click:async function(){
        
    if(!_this.data.dir1_id){
      let path_l=_this.data.path.split(".");
      _this.data.dir1_id=path_l[path_l.length-4];
      _this.data.dir2_id=path_l[path_l.length-3];
      _this.data.temp_id=path_l[path_l.length-2];
      _this.data.version_id=path_l[path_l.length-1];
  }
    
        response4 = await fetch(urls.下载用户的前端组件库组件版本_url, {  
          method: 'POST', // 指定请求方法为 POST  
          headers: {  
            'Content-Type': 'application/json', // 设置请求头，表明发送的是 JSON 数据  
            // 可能还需要设置其他请求头，比如 'Authorization' 用于身份验证  
          },  
          body: JSON.stringify({"down_user_id":cookie_read("easyedit_userid"),"dir1_id":_this.data.dir1_id,"dir2_id":_this.data.dir2_id,"temp_id":_this.data.temp_id,"version_id":_this.data.version_id,"request_id":_this.data.generateRandomString(10)}), // 将 JSON 字符串作为请求体发送  
        });  
          data4 = await response4.json();
          if(data4.type=='wait'){

            Vue.prototype.$notify({type: 'info',message: '下载人数过多，当前排队:'+data4.num})
          }else{
            window.location.href =data4.down_url;
          }
          
          },
      },
    // 2:{
    //     icon_class:"icon iconfont icon-refresh",
    //     hovertext:"刷新前端组件版本列表",
    //     add_show:false,
    //     click:async function(){
    //         /*console.log("开始刷新目录");*/
    //         _this.data.刷新前端组件();
    //     }
    //     },
    300:{

    icon_class:"icon iconfont icon-upload",
    hovertext:"更新代码",
    add_show:false,
    click:async function(){
        // console.log("update_my_temp_from_flag",_this.update_my_temp_from_flag)
    //初始化上传文件夹回调函数
    if(!_this.eeeeeeeeeess){
        // console.log("开始初始化")
      ttime3(_this,"add_temp",function(){
        // console.log("...>?")
          _this.$refs.add_temp.addEventListener('change', function(event) {  
            // 在这里执行你的函数  
            // console.log("_this.files","event.target.files)
            _this.files=event.target.files; 
            // console.log("_this.files",_this.files)
            if(!_this.data.dir1_id){
                let path_l=_this.data.path.split(".");
                _this.data.dir1_id=path_l[path_l.length-4];
                _this.data.dir2_id=path_l[path_l.length-3];
                _this.data.temp_id=path_l[path_l.length-2];
                _this.data.version_id=path_l[path_l.length-1];
            }
        }); 
      })
      _this.eeeeeeeeeess=true;
    }
    _this.update_my_temp_from_flag=true;



},
    },
}
_this.data.update_temp=async function(){
       
      let MAX_SIZE=10*1024*1024;
        // 创建一个 FormData 实例  
      add_my_temp_formData = new FormData();  
      let max_size=0;
      // 遍历文件列表，将文件添加到 formData  
      let i=0;
    //   console.log("_this.files",_this.files)
    //   window.ddddd=_this.files
      for (let file of _this.files) {  
        i++;
        max_size=max_size+file.size;
        if (max_size>MAX_SIZE){
          this.$message({
            type: 'info',
            message: '超过上传最大值:'+MAX_SIZE/1024/1024+'M'
          });
          return
        }
        add_my_temp_formData.append('file_'+i, file); // 'files[]' 是服务器接收文件时可能使用的字段名，具体取决于后端配置  
        add_my_temp_formData.append(`file_path${i}`,file.webkitRelativePath);
      }  
      // 添加额外的参数  
      add_my_temp_formData.append('type', 'add_my_temp');  
      add_my_temp_formData.append('dir1_id',_this.data.dir1_id);  
      add_my_temp_formData.append('dir2_id',_this.data.dir2_id);  
      add_my_temp_formData.append('temp_id', _this.data.temp_id);  
      add_my_temp_formData.append('version_id', _this.data.version_id);  
      console.log("add_my_temp_formData",add_my_temp_formData)
    //   add_my_temp_formData.append("path",file.webkitRelativePath)
      // 发送请求到服务器  
      try {  
        const response = await fetch(urls.更新前端组件版本代码_url, {  
          method: 'POST',  
          body: add_my_temp_formData,  
        });  
  
        if (!response.ok) {  
          throw new Error('Network response was not ok');  
        }  
  
        const received_data = await response.json(); // 假设服务器返回 JSON 数据  
        if(received_data.type=="success"){
            
          Vue.prototype.$notify({type: 'success',message: received_data.message||'操作成功'})
        }else{
            
          Vue.prototype.$notify({type: 'error',message: received_data.message||'操作失败'})
        }
      _this.update_my_temp_from_flag=false;//关闭对话框
    
      } catch (error) {  
        console.error('Error:', error);  
      } 
}

}

})